home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: tony@online.tmx.com.au (Tony Cook)
- Newsgroups: comp.std.c++
- Subject: Re: Article for comp.std.c++: Eliminating #ifdef: if const
- Date: 20 Feb 1996 10:48:56 PST
- Organization: Home
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <199602190008.LAA23411@online.tmx.com.au>
- References: <199602160807.IAA06126@condor.ukc.ac.uk>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: Mon, 19 Feb 1996 11:08:06 +1100
- X-Newsreader: TIN [version 1.2 PL2]
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMSoXpky4NqrwXLNJAQE4DwH+Lct7p4PNDix8hhGra5dehRyQZV3Z+Onh
- rhNmgBmHyGiHSc7K0zN1P9YtiTIh8pybI55LlWCMYJNIYeVMVEZ7/Q==
- =BrSV
- Originator: austern@isolde.mti.sgi.com
-
- Mark Russell (M.T.Russell@ukc.ac.uk) wrote:
- : Subject: Eliminating #ifdef: if const
-
- : Here's an idea I had for a non-preprocessor replacement for #if and #ifdef.
-
- : if const (<expr>) { <stuff> }
-
- : `if const' is a compile time version of `if'. <expr> is a constant
- : expression which is convertible to bool. If it yields true, <stuff>
- : is processed as normal. Otherwise <stuff> is parsed into tokens, but
- : ignored except for counting { and } nesting. <stuff> is anything that
- : can appear inside a namespace block. `if const' does not introduce a
- : new scope.
-
- : The following is also legal, with the obvious meaning:
-
- : if const (<expr>) { <stuff> } else const { <other stuff> }
-
- : There are also a number of compile-time pseudo-functions (I hesitate
- : to call them pragmas):
-
- : bool #os_version(const char* str)
-
- : os version (uname -r) at or later than str
-
- : bool #os_name(const char *str)
-
- : os name (uname -s) is str
-
- These would require mechanisms to supply operating system parameters
- to the compiler - besides, a module compiled for one operating
- system can sometimes be linked into an executable for another on
- (some 16-bit DOS modules can be used in a Windows program).
-
- OS/2 FAPI programs can run under DOS, OS/2 or Windows NT.
-
- : bool #compiler_name(const char *)
- : bool #compiler_version(const char*)
-
- : Same tests for the compiler
-
- These might be nice.
-
- : Using these you could do things like this:
-
- : // Are we running IRIX 5.3
- : const bool using_irix_53 = #os_name("IRIX") &&
- : #os_version("5.3") && !#os_version("5.4")
-
- : if const (using_irix_53) {
- : // Do some stuff needed just for IRIX 5.3
- : }
-
- : if const (#compiler("g++")) {
- : // Do some g++ stuff
- : }
-
- : if const (#header_exists("sys/frobnitz9000.h")) {
- : #include "sys/frobnitz9000.h"
- : // Do stuff for the Frobnitz 9000
- : }
-
- Doesn't this bind the preprocess and compiler closer together? For
- the compilation stages in the WP won't the #include occur in stage 4
- and the if const in stage 7?
-
- : With this I could personally stop using the preprocessor for anything
- : except #include. If `include' (as described in D&E) is also
- : implemented, I could stop using the preprocessor altogether, which
- : would be nice.
-
- What's the difference between what you've specified and the
- preprocessor (other than different syntax?)
-
- --
- Tony Cook - tony@online.tmx.com.au
- 100237.3425@compuserve.com
- ---
- [ To submit articles: Try just posting with your newsreader. If that fails,
- use mailto:std-c++@ncar.ucar.edu
- FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
- Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
- Comments? mailto:std.c++-request@ncar.ucar.edu
- ]
-